<PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>YUI io Transaction Events Tests</title>
</head>

<body class="yui3-skin-sam">
<h1>YUI io Transaction Events Tests</h1>

<script type="text/javascript" src="../../../build/yui/yui.js"></script>
<script type="text/javascript">

(function() {
    YUI({
        base: "../../../build/",
        filter: "debug",
        logExclude: {
            attribute: true,
            dom: true,
            node: true,
            event: true,
            base: true,
            widget: true,
            selector: true,
            io: true
        },
        useConsole: true
    }).use("test", "console", "io-base", function(Y) {

        var console = new Y.Console().render();
		var ioTransactionEventFlowTest = new Y.Test.Case(
        {
        	name: 'Transaction flow test',
        	testSuccess: function() {
        		var actual = [], t = this;
        		this.success = ['start', 'complete', 'success', 'end'],
        		this.compare = function() {
					for (var i=0; i < 4; i++) {
						Y.log(actual[i]);
						Y.Assert.areSame(t.success[i], actual[i]);
					}
        		};
        		Y.io('http.php?a=200', {
        			on: {
        				start: function() {
        					actual.push('start');
        				},
        				complete: function() {
        					actual.push('complete');
        				},
        				success: function() {
        					actual.push('success');
        				},
        				end: function() {
        					actual.push('end');
        					t.resume(t.compare);
        				}
        			}
        		});
        		this.wait(null, 1000);
        	},
        	test404Failure: function() {
        		var actual = [], t = this;
        		this.failure = ['start', 'complete', 'failure', 'end'],
        		this.compare = function() {
					for (var i=0; i < 4; i++) {
						Y.log(actual[i]);
						Y.Assert.areSame(t.failure[i], actual[i]);
					}
        		};
        		Y.io('404.html', {
        			on: {
        				start: function() {
        					actual.push('start');
        				},
        				complete: function() {
        					actual.push('complete');
        				},
        				failure: function() {
        					actual.push('failure');
        				},
        				end: function() {
        					actual.push('end');
        					t.resume(t.compare);
        				}
        			}
        		});
        		this.wait(null, 1000);
        	},
        	test500Failure: function() {
        		var actual = [], t = this;
        		this.failure = ['start', 'complete', 'failure', 'end'],
        		this.compare = function() {
					Y.Assert.areSame(500, t.status);
					for (var i=0; i < 4; i++) {
						Y.Assert.areSame(t.failure[i], actual[i]);
					}
        		};
        		Y.io('http.php?a=500', {
        			on: {
        				start: function() {
        					actual.push('start');
        				},
        				complete: function(id, o, a) {
        					actual.push('complete');
        				},
        				failure: function(id, o, a) {
        					actual.push('failure');
        					t.status = o.status;
        				},
        				end: function() {
        					actual.push('end');
        					t.resume(t.compare);
        				}
        			}
        		});
        		this.wait(null, 1000);
        	},
        	testHttpException: function() {
        		var actual = [], t = this;
        		this.failure = ['start', 'complete', 'failure', 'end'],
        		this.compare = function() {
        			Y.log(t.status);
					for (var i=0; i < 4; i++) {
						Y.Assert.areSame(t.failure[i], actual[i]);
					}
        		};
        		Y.io('http.php?a=999', {
        			on: {
        				start: function() {
        					actual.push('start');
        				},
        				complete: function() {
        					actual.push('complete');
        				},
        				failure: function(id, o, a) {
        					actual.push('failure');
        					t.status = o.status;
        				},
        				end: function() {
        					actual.push('end');
        					t.resume(t.compare);
        				}
        			}
        		});
        		this.wait(null, 1000);
        	},
        	test304: function() {
        		var actual = [], t = this;
        		this.success = ['start', 'complete', 'end'],
        		this.compare = function() {
        			Y.log(t.status);
					for (var i=0; i < 3; i++) {
						Y.Assert.areSame(t.success[i], actual[i]);
					}
        		};
        		Y.io('http.php?a=304', {
        			on: {
        				start: function() {
        					actual.push('start');
        				},
        				complete: function() {
        					actual.push('complete');
        				},
        				end: function() {
        					actual.push('end');
        					t.resume(t.compare);
        				}
        			}
        		});
        		this.wait(null, 1000);
        	}
        });
		Y.Test.Runner.add(ioTransactionEventFlowTest);
		Y.Test.Runner.run();
	})
})();
</script>
</body>
</html>
